package com.qyc.controller;

import com.qyc.dto.AddOrUpdateAnimalDTO;
import com.qyc.service.AnimalService;
import com.qyc.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: AnimalController
 * @Description: 动物管理相关Controller层
 * @author: qinyc
 * @date: 2023/6/25 10:53
 * @version: v1.0
 */
@Api(tags = "动物管理")
@RestController
@RequestMapping("/animal")
public class AnimalController {
    @Autowired
    private AnimalService animalService;
    
    /**
     * @Author qinyc
     * @Description  分页多条件查询动物基本信息以及对应批次信息、栏圈信息以及栏舍信息
     * @version: v1.0
     * @Date 10:56 2023/6/25
     **/
    @ApiOperation("分页多条件查询动物基本信息以及对应批次信息、栏圈信息以及栏舍信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页大小"),
            @ApiImplicitParam(name = "aHealthy",value = "健康状态"),
            @ApiImplicitParam(name = "aGender",value = "性别")
    })
    @GetMapping("/query")
    public ResponseResult queryPage(Integer pageNum,Integer pageSize,String aHealthy,String aGender){
        return animalService.queryPage(pageNum,pageSize,aHealthy,aGender);
    }
    
    /**
     * @Author qinyc
     * @Description  根据动物ID生成对应的二维码信息
     * @version: v1.0
     * @Date 12:07 2023/6/25
     **/
    @ApiOperation("根据动物ID生成对应的二维码信息")
    @GetMapping("/QRcode")
    public ResponseResult qrCode(String animalId){
        return animalService.qrCode(animalId);
    }
    
    /**
     * @Author qinyc
     * @Description 根据动物编号查询动物基本信息以及对应批次信息、栏圈信息以及栏舍信息
     * @version: v1.0
     * @Date 12:49 2023/6/25
     **/
    @ApiOperation("根据动物编号查询动物基本信息以及对应批次信息、栏圈信息以及栏舍信息")
    @GetMapping("/findByAnimalId")
    public ResponseResult findByAnimalId(String animalId){
        return animalService.findByAnimalId(animalId);
    }

    /**
     * @Author qinyc
     * @Description  新增或修改动物
     * @version: v1.0
     * @Date 20:08 2023/6/25
     **/
    @ApiOperation("新增或修改动物")
    @PostMapping("/saveOrUpdate")
    public ResponseResult saveOrUpdate(@RequestBody AddOrUpdateAnimalDTO addOrUpdateAnimalDTO){
        return animalService.saveOrUpdateAnimal(addOrUpdateAnimalDTO);
    }
    
    /**
     * @Author qinyc
     * @Description  根据ID删除动物
     * @version: v1.0
     * @Date 20:33 2023/6/25
     **/
    @ApiOperation("根据ID删除动物")
    @DeleteMapping("/deleteById/{aAnimalId}")
    public ResponseResult deleteById(@PathVariable("aAnimalId") String aAnimalId){
        return animalService.deleteById(aAnimalId);
    }

    /**
     * @Author qinyc
     * @Description  批量删除动物
     * @version: v1.0
     * @Date 20:48 2023/6/25
     **/
    @ApiOperation("批量删除动物")
    @DeleteMapping("/deleteByIdAll")
    public ResponseResult deleteByIdAll(@RequestBody List<String> animalIds){
        return animalService.deleteByIdAll(animalIds);
    }
}
